package com.itheima.reggie.mapper;

import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper {

    /**
     * 根据分类id查询是否有关联的套餐
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> findSetmealByCategoryId(long categoryId);

    /**
     * 分页条件查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    List<Setmeal> findAllSetmeal(int page, int pageSize, String name);

    /**
     * 新增套餐，并回显自动增长的id
     * @param setmealDto
     * @return
     */
    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int addSetmeal(SetmealDto setmealDto);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal findSetmealById(Long id);

    /**
     * 更新套餐
     * @param setmealDto
     * @return
     */
    int updateSetmeal(SetmealDto setmealDto);

    /**
     * 更新套餐状态
     * @param status
     * @param ids
     * @return
     */
    int updateSetmealStatusByIds(@Param("status") int status, @Param("ids")long[] ids);

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    int deleteSetmealByIds(@Param("ids") Long[] ids);

    /**
     * 批量查询套餐是否在售
     * @param ids
     * @return
     */
    int findSetmealIsSaleByIds(@Param("ids") Long[] ids);

    @Select("select * from setmeal where category_id = #{categoryId} and status = #{status}")
    List<Setmeal> findSetmealByCategoryIdAndStatus(@Param("categoryId")Long categoryId, @Param("status")Integer status);
}
